package com.aplink.generic.webservice.pojo;

import android.text.TextUtils;

import com.aplink.generic.cache.MasterConfigManager;
import com.aplink.generic.pojo.ContentData;
import com.aplink.generic.pojo.GenericObject;
import com.aplink.generic.pojo.ObjPropInfo;
import com.aplink.generic.pojo.WebserviceConfig;
import com.google.gson.JsonObject;

public class Login {
	public static Login read(GenericObject genericObject,
	        ContentData contentData) {
		Login login = new Login();
		JsonObject jsonObject = new JsonObject();
		for (int i = 0; i < contentData.size(); i++) {
			ObjPropInfo column = contentData.valueAt(i);
			String property = contentData.getWebserviceParameter(column);
			String value = genericObject.getValue(column);
			if (!TextUtils.isEmpty(property) && !TextUtils.isEmpty(value)) {
				jsonObject.addProperty(property, value);
			}
		}
		login.setJsonValue(jsonObject.toString());
		login.setLoginEndPoint(contentData.getWebserviceFunction());
		return login;
	}
	private String mJsonValue;

	private String mLoginEndPoint;

	public String getJsonValue() {
		return mJsonValue;
	}

	public String getLoginEndPoint() {
		return mLoginEndPoint;
	}

	public String getLoginRequest() {
		WebserviceConfig webserviceConfig = MasterConfigManager.getInstance()
		        .get().getWebserviceConfig();
		return String.format(webserviceConfig.getWebserviceDomain()
		        + mLoginEndPoint + "jsonValue=%s", mJsonValue);
	}

	public void setJsonValue(String jsonValue) {
		mJsonValue = jsonValue;
	}

	public void setLoginEndPoint(String loginEndPoint) {
		mLoginEndPoint = loginEndPoint;
	}
}
